/**
 *    CTR - Centro Tecnologia Rocci
 *    Open Source Java Classic Game Toolkit
 *
 *    (C) 2010, CTR - Centro Tecnologia Rocci
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 */
package it.ctr.game.toolkit.stage;

import it.ctr.game.toolkit.BackgroundRenderer;
import it.ctr.game.toolkit.BrickBox;
import it.ctr.game.toolkit.GameComponent;
import it.ctr.game.toolkit.component.Mario;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

import com.mojang.mario.level.BgLevelGenerator;
import com.mojang.mario.level.LevelGenerator;

/**
 * @author Luca Rocci, 10/ago/2010 @
 */
public class TitleStage extends Stage {
	private GameComponent component;
	private int tick;
	private BackgroundRenderer[] backgroundLayer = new BackgroundRenderer[2];

	public TitleStage(GameComponent component, GraphicsConfiguration gc) {
		this.component = component;
		backgroundLayer[0] = new BackgroundRenderer(BgLevelGenerator.createLevel(2048,30, LevelGenerator.SKY), gc, GameComponent.WIDTH, GameComponent.HEIGHT, 1);
		backgroundLayer[1] = new BackgroundRenderer(BgLevelGenerator.createLevel(2048,30, LevelGenerator.LANDSCAPE), gc, GameComponent.WIDTH, GameComponent.HEIGHT, 2);
	}

	public void init() {
		BrickBox.startMusic(4);
	}

	public void render(Graphics g, float alpha) {
		  g.setColor(Color.WHITE);
          g.fillRect(0, 0, GameComponent.WIDTH, GameComponent.HEIGHT);

		//		for (int i = 0; i < 2; i++) {
//			backgroundLayer[i].setCam(tick + GameComponent.WIDTH/2, 16);
//			backgroundLayer[i].render(g, tick, alpha);
//		}
//		int yo = 16 - Math.abs((int) (Math.sin((tick + alpha) / 6.0) * 8));
		//g.drawImage(BrickBox.title, 100, yo, null);
		g.drawImage(BrickBox.logo, (GameComponent.WIDTH/2)-(BrickBox.logo.getWidth(null)/2), 100, null);
		
        if (tick/4%2==0)
        {
            String msg = "Premi Start (s)";
            BrickBox.drawString(g, msg, (GameComponent.WIDTH/2) - msg.length() * 4 + 1, 210 + 1, 0);
            BrickBox.drawString(g, msg, (GameComponent.WIDTH/2) - msg.length() * 4, 210, 7);
        }
  
	}

	private boolean wasDown = true;

	public void tick() {
		tick++;
		if (!wasDown && keys[Mario.KEY_JUMP]) {
			component.startGame();
		}
		if (keys[Mario.KEY_JUMP]) {
			wasDown = false;
		}
	}

	public float getX(float alpha) {
		return 0;
	}

	public float getY(float alpha) {
		return 0;
	}

}
